package com.zbkj.service.service.enquiry.impl;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zbkj.common.model.enquiry.PeEnquiry;
import com.zbkj.common.model.project.ProjectInfo;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.enquiry.ReportRequest;
import com.zbkj.common.response.enquiry.EnquiryReportResponse;
import com.zbkj.service.dao.enquiry.PeEnquiryMapper;
import com.zbkj.service.service.enquiry.IPeEnquiryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 设备询价记录表 服务实现类
 * </p>
 *
 * @author 
 * @since 2025-07-29
 */
@Service
public class PeEnquiryServiceImpl extends ServiceImpl<PeEnquiryMapper, PeEnquiry> implements IPeEnquiryService {

    @Override
    public PageInfo<PeEnquiry> getUserEnquiryList(Long userId, PageParamRequest pageParamRequest) {
        List<PeEnquiry> list = this.lambdaQuery().eq(PeEnquiry::getUserId, userId).eq(PeEnquiry::getDeleteFlag, 0).orderByDesc(PeEnquiry::getCreateTime).list();
        Page<ProjectInfo> pageObj = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return CommonPage.copyPageInfo(pageObj, list);
    }

    @Override
    public EnquiryReportResponse enquiryReqort(Long userId, ReportRequest reportRequest) {
        List<PeEnquiry> list = this.lambdaQuery().eq(PeEnquiry::getUserId, userId).eq(PeEnquiry::getDeleteFlag, 0)
                .le(PeEnquiry::getCreateTime, reportRequest.getEndDate())
                .ge(PeEnquiry::getCreateTime, reportRequest.getStartDate())
                .list();
        EnquiryReportResponse enquiryReportResponse =  new EnquiryReportResponse();

        if(ObjectUtils.isNotEmpty(list)){
            enquiryReportResponse.setEnquiryCounts(list.size());
            enquiryReportResponse.setPeopleCounts((int) list.stream().map(PeEnquiry::getUserId).distinct().count());
        }
        return enquiryReportResponse;
    }
}
